package com.cai.servlet.common.topic;

import com.cai.dao.DetailedTopicDao;
import com.cai.dao.impl.DetailedTopicDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author RuoLi
 */
@WebServlet(name = "ServletDetailedTopicInfoPage", value = "/common/detailedTopicPage")
public class ServletDetailedTopicPage extends HttpServlet {
    DetailedTopicDao topicDao = new DetailedTopicDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        int currentPage = Integer.parseInt(req.getParameter("currentPage"));
        int pageSize = Integer.parseInt(req.getParameter("pageSize"));
        String data = topicDao.getDetailedTopicData(currentPage, pageSize);
        resp.getWriter().write(data);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //发送页数数据
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        int currentPage = Integer.parseInt(req.getParameter("currentPage"));
        int pageSize = Integer.parseInt(req.getParameter("pageSize"));
        String data = topicDao.getDetailedTopicPageData(currentPage, pageSize);
        resp.getWriter().write(data);
    }
}
